package com.googlecode.perfectable.persistable.index;

import com.googlecode.perfectable.persistable.session.Identifier;
import com.googlecode.perfectable.persistable.session.InvalidReference;
import com.googlecode.perfectable.persistable.storage.Materializer;

public class StandardReference<T> implements Reference<T> {
	private final Materializer storage;
	private final Identifier<T> identifier;

	private StandardReference(Materializer storage, Identifier<T> identifier) {
		this.storage = storage;
		this.identifier = identifier;
	}

	public static <X> StandardReference<X> create(Materializer storage, Identifier<X> identifier) {
		return new StandardReference<>(storage, identifier);
	}

	@Override
	public T materialize() throws InvalidReference {
		return this.storage.materialize(this.identifier);
	}

	@Override
	public Identifier<T> identifier() {
		return this.identifier;
	}
}
